/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.ui.tests.viewers;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeViewer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import org.eclipse.ui.model.WorkbenchLabelProvider;

import org.reliablesource.client.ui.viewers.ReliableViewer;

import org.reliablesource.symbiosys.workbench.tests.TestPlugin;

import java.util.ArrayList;
import java.util.Collections;


/**
 *
 * MockSelectorViewer.java<br>
 * Created on: Jun 27, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com">Dennis Park</a>
 *
 * @category
 * @since 1.0
 */
public class MockSelectorViewer extends ReliableViewer {
    //	An arbitrary child Viewer that has a control.
    private TreeViewer treeViewer;

    public MockSelectorViewer() {
        super();
    }

    /*
     * (non-Javadoc)
     * @see com.cisco.nm.cmp.client.ui.viewers.CMPViewer#createViewerControl(org.eclipse.swt.widgets.Composite)
     */
    @Override
    public void createViewerControl(Composite _contentParent) {
        treeViewer = new TreeViewer(_contentParent,
                SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

        treeViewer.setContentProvider(new MockObjectContentProvider());
        treeViewer.setLabelProvider(new WorkbenchLabelProvider());
        contentComposite = (Composite) treeViewer.getControl();
        addChild(treeViewer);
        contentComposite.pack();
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.jface.viewers.Viewer#getSelection()
     */
    @Override
    public ISelection getSelection() {
        return treeViewer.getSelection();
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.jface.viewers.Viewer#refresh()
     */
    @Override
    public void refresh() {
        treeViewer.refresh();
        super.refresh();
    }

    /*
     * (non-Javadoc)
     * @see com.cisco.nm.cmp.client.ui.viewers.CMPViewer#setInput(java.lang.Object)
     */
    @Override
    public void setInput(final Object _input) {
        ArrayList _list_;

        if (!(_input instanceof Collections)) {
            _list_ = new ArrayList();

            if (_input != null)
                _list_.add(_input);

            treeViewer.setInput(_list_);
        } else
            treeViewer.setInput(_input);

        refresh();
    }

    /*
     * (non-Javadoc)
     * @see com.cisco.nm.cmp.client.ui.viewers.CMPViewer#getControl()
     */
    @Override
    public Control getControl() {
        return treeViewer.getControl();
    }

    /*
     * (non-Javadoc)
     * @see com.cisco.nm.cmp.client.ui.viewers.CMPViewer#getInput()
     */
    @Override
    public Object getInput() {
        if (null != treeViewer)
            return treeViewer.getInput();

        return TestPlugin.NULL_OBJECT[0];
    }

    /* (non-Javadoc)
     * @see org.reliablesource.client.ui.viewers.IReliableViewer#setFocus()
     */
    public boolean setFocus() {
        return getControl().setFocus();
    }
}
